package change;

import affilication.Affiliation;
import affilication.imp.NoAffiliation;
import affilication.imp.UnionAffiliation;
import domain.Employee;
import exception.EmployeeException;

public class ChangeUnaffiliatedTransaction extends ChangeAffiliationTransaction {

    public ChangeUnaffiliatedTransaction(int empId) {
        super(empId);
    }

    @Override
    public Affiliation getAffiliation() {
        return new NoAffiliation();
    }

    @Override
    public void execute() throws EmployeeException {
        Employee employee = payrollDatabase.getEmployee(getEmpId());
        Affiliation affiliation = employee.getAffiliation();
        if(affiliation instanceof UnionAffiliation) {
            UnionAffiliation unionAffiliation = (UnionAffiliation) affiliation;
            int memberId = unionAffiliation.getMemberId();
            payrollDatabase.deleteUnionMember(memberId);
        }

        super.execute();
    }
}
